<?php
require("../../class/connect.php");
include("../../class/db_sql.php");
include("../../class/config.php");
include("../../class/functions.php");
$link=db_connect();
$empire=new mysqlquery();
$logininid=getcvar('loginuserid');
$loginin=getcvar('loginusername');
$loginrnd=getcvar('loginrnd');
$loginlevel=getcvar('loginlevel');
$editor=1;
is_login($logininid,$loginin,$loginrnd);
//验证权限
CheckLevel($logininid,$loginin,$classid,"totaldata");
$tbname=RepPostVar($_GET['tbname']);
if(empty($tbname))
{
	$tbname=$public_r['tbname'];
}
//数据表
$b=0;
$htb=0;
$tbsql=$empire->query("select tbname,tname from {$dbtbpre}enewstable order by tid");
while($tbr=$empire->fetch($tbsql))
{
	$b=1;
	$select="";
	if($tbr[tbname]==$tbname)
	{
		$htb=1;
		$select=" selected";
	}
	$tbstr.="<option value='".$tbr[tbname]."'".$select.">".$tbr[tname]."</option>";
}
if($b==0)
{
	printerror('ErrorUrl','');
}
if($htb==0)
{
	printerror('ErrorUrl','');
}
//用户
$sql=$empire->query("select userid,username from {$dbtbpre}enewsuser order by userid");
//风格
$loginadminstyleid=(int)getcvar('loginadminstyleid');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>用户发布统计</title>
<link href="../adminstyle/<?=$loginadminstyleid?>/adminstyle.css" rel="stylesheet" type="text/css">
<style>
table#tb td{text-align:center;}
</style>
</head>

<body>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
  <tr> 
    <td height="25">位置：<a href="UserTotal.php">用户发布统计</a></td>
  </tr>
  <tr>
    <td height="30"> 选择统计数据表： 
      <select name="tbname" id="tbname" onchange="window.location='UserTotal.php?tbname='+this.options[this.selectedIndex].value">
	  <?=$tbstr?>
      </select>
    </td>
  </tr>
</table>

<table id=tb width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
  <tr class="header"> 
    <td width="12%" height="25"> 
      <div align="center">用户</div></td>
    <td width="13%" height="25">今天发布数</td>
    <td width="13%" height="25">昨天发布数</td>
    <td width="13%" height="25">本月发布数</td>
    <td width="13%" title="此列数据不包含未审核文章">本季度发布数</td>
    <td width="13%">总发布数</td>
    <td width="13%">未审核数</td>
    <td width="10%"></td>
  </tr>
  <?php
  $totime=time();
  $today=date("Y-m-d");
  $yesterday=date("Y-m-d",$totime-24*3600);
  $month=date("Y-m");
  $maxmonth=date("Y-m");
  //如果是季度统计
  switch($m=date("m")){
    case $m/3<=1 :
      $quartermonth=date("Y")."-1";
    case $m/3<=2 :
      $quartermonth=date("Y")."-04";
      break;
    case $m/3<=3 :
      $quartermonth=date("Y")."-07";
      break;
    case $m/3<=4 :
      $quartermonth=date("Y")."-10";
      break;
  }
  //本月最大天数
  $maxday=date("t",mktime(0,0,0,date("m"),date("d"),date("Y")));
  
  while($r=$empire->fetch($sql))
  {
  	$tquery="select count(*) as total from {$dbtbpre}ecms_".$tbname." where userid='$r[userid]' and ismember=0";
  	//今天发布数
  	$todaynum=$empire->gettotal($tquery." and truetime>=".to_time($today." 00:00:00")." and truetime<=".to_time($today." 23:59:59"));
	//昨天发布数
	$yesterdaynum=$empire->gettotal($tquery." and truetime>=".to_time($yesterday." 00:00:00")." and truetime<=".to_time($yesterday." 23:59:59"));
	//本月发布数
	$monthnum=$empire->gettotal($tquery." and truetime>=".to_time($month."-01 00:00:00")." and truetime<=".to_time($month."-".$maxday." 23:59:59"));
	//本季度已审核发布数
	$quarternum=$empire->gettotal($tquery." and truetime>=".to_time($quartermonth."-01 00:00:00")." and truetime<=".to_time($maxmonth."-".$maxday." 23:59:59")." and checked=1" );
	//所有文章数
	$totalnum=$empire->gettotal($tquery);
	//未审核文章数
	$nochecktotalnum=$empire->gettotal($tquery." and checked=0");
	//已审核文章数
	//$checktotalnum=$empire->gettotal($tquery." and checked=1");
  ?>
  <tr bgcolor="#FFFFFF"> 
    <td height="25"><div align="center"><a href="AddUser.php?enews=EditUser&userid=<?=$r[userid]?>" target="_blank">
        <u><?=$r[username]?></u>
        </a></div></td>
    <td height="25"><div align="center"> 
        <?=$todaynum?>
      </div></td>
    <td height="25"><?=$yesterdaynum?></td>
    <td height="25"><?=$monthnum?></td>
    <td height="25"><a href="../ListAllInfo.php?showspecial=6&keyboard=<?=$r[username]?>&show=2&tbname=<?=$tbname?>&sear=1" target="_blank"><u><?=$quarternum?></u></a></td>
    <td><a href="../ListAllInfo.php?keyboard=<?=$r[username]?>&show=2&tbname=<?=$tbname?>&sear=1" target="_blank"><u><?=$totalnum?></u></a></td>
    <td><a href="../ListAllInfo.php?showspecial=4&keyboard=<?=$r[username]?>&show=2&tbname=<?=$tbname?>&sear=1" target="_blank"><u><?=$nochecktotalnum?></u></a></td>
    <td><a href="#ecms" onclick="window.open('MoreUserTotal.php?tbname=<?=$tbname?>&userid=<?=$r[userid]?>&username=<?=$r[username]?>','ViewUserTotal','width=360,height=500,scrollbars=yes,left=300,top=150,resizable=yes');">[详细]</a></td>
  </tr>
  <?php
  }
  ?>
</table>
</body>
</html>
<?php
db_close();
$empire=null;
?>